<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH.'third_party/uc_client/config.inc.php'; 
require_once APPPATH.'third_party/uc_client/client.php'; 
 
/**
 * Smarty Class 
 *
 * Lets you use smarty engine in CodeIgniter.
 *
 * @package		Application
 * @subpackage	Libraries
 * @category	Customize Class
 * @author		sitearth
 * @link		blog.sitearth.com
 */
class CI_Ucenter {

	var $CI;

	/**
	 * Smarty constructor
	 *
	 * The constructor runs the session routines automatically
	 * whenever the class is instantiated.
	 */
	public function __construct()
	{
	}
	
	public function avatar($uid,$size='small',$type='virtual')
	{
		if($type=="upload"){
			return uc_avatar($uid,$type);
		}else{
		$src=UC_API.'/avatar.php?uid='.$uid.'&type='.$type.'&size='.$size;
		header('location:'.$src);
		} 
	}
	
	public function isauth()
	{
		$authcode=get_cookie('authcode');
		$username=get_cookie('username');
		$uid=get_cookie('uid');
		if(uc_authcode($uid."\t".$username, 'ENCODE')!=$authcode){
			$username=$this->session->userdata('username');
			$uid=$this->session->userdata('uid');
		}
		echo $authcode;
		if($uid>0){
			return array(
		'uid' => $uid,
		'username' => $username
		);
		}else{
			return false;
		}
	}
	
	public function auth($uid,$username,$remember=true){
		
		$session = array(
		'uid' => $uid,
		'username' => $username
		);
		echo $session;
		$this->session->set_userdata($session);
		if($remember){
		set_cookie('authcode', uc_authcode($uid."\t".$username, 'ENCODE'), '86500');
		set_cookie('username', $username, '86500');
		set_cookie('uid', $uid, '86500');
		}
	}
	
	public function logout(){
		return uc_user_synlogout();
	}

}
/* End of file Smarty.php */
/* Location: ./application/libraries/Smarty.php */
